
var XgPlayer = {
	'Url': "ftp://pub:pub@.domain.com:20320/421/00.mp4",
	'NextcacheUrl': "ftp://pub:pub@.domain.com:20320/421/01.mp4",
	'LastWebPage': '',
	'NextWebPage': "http://www.xx.com/xxx.html",
	'Buffer': 'http://js.client51.com/xg_loading.html',
	'Pase': 'http://js.client51.com/xg_loading.html',
	'Width': '100%',
	'Height': MacPlayer.Height,
	'Second': 8,
	"Installpage": 'http://js.client51.com/installpage.html'
}; 

/* document.write('<script language="javascript" src="http://js.client51.com/m_xiguaplayer.js" charset="utf-8"></script>'); */

document.writeln("<div id=\"xg_box\"></div>");
if (XgPlayer.Second < 1) {
    XgPlayer.Second = 1;
}
var browser;
var installflag = 1;
function $XghdInstall() {
    $$("xg_box").style.display = "none";
    if (installflag == 1) {
        document.writeln('<iframe border="0" src="' + XgPlayer.Installpage + '" marginWidth="0" frameSpacing="0" marginHeight="0" frameBorder="0" noResize scrolling="no" width="' + XgPlayer.Width + '" height="' + XgPlayer.Height + '" vspale="0" ></iframe>');
        installflag = 0;
    }
}
var AdsBeta6 = {
    'Start': function () {
        $$('buffer').style.display = 'block';
        if (xiguaPlayer.IsBuffing()) {
            $$('buffer').height = XgPlayer.Height - 80;
        } else {
            $$('buffer').height = XgPlayer.Height - 60;
        }
    },
    'End': function () {
        if (!XgPlayer.Second) {
            $$('buffer').style.display = 'none';
            $$('xiguaPlayer').style.display = 'block';
            xiguaPlayer.height = XgPlayer.Height;
        }
    },
    'Status': function () {
        if (xiguaPlayer.IsPlaying()) {
            this.End();
        } else {
            this.Start();
        }
    }
}
function $$(id) {
    return document.getElementById(id);
}
function $Showhtml() {
    browser = navigator.appName;
   // alert(navigator.userAgent);
    if (browser == "Netscape" || browser == "Opera") {
        if (/iPad|iPhone/i.test(navigator.userAgent)) {
            setTimeout($PlayerIOS, 1000);
        }

        if (/Android/i.test(navigator.userAgent)) {

            $PlayerAndroid();
        }
        if (isIE()) {
            return $PlayerIe();
        } else {
            return $PlayerNt();
        }
    } else if (browser == "Microsoft Internet Explorer") {
        return $PlayerIe();
    }
    else {
        alert('请使用IE内核浏览器观看本站影片!');
    }
}
function isIE() {
    if (!!window.ActiveXObject || "ActiveXObject" in window) {
        browser = "Microsoft Internet Explorer";
        return true;
    }
    return false;
}


function installapp() {
    return function () {
        var clickedAt = +new Date;
        setTimeout(function () {
            try {
                if (isxg()) {
                    return;
                }
            } catch (e) {
                ;
            }
            if (+new Date - clickedAt < 1500) {
                setTimeout(function () {
                    var surl = "https://itunes.apple.com/cn/app/桃桃播放器/id1189520769?l=en&mt=8";
                    top.location.href = surl;
                }, 3000);
            }
        }, 500);
    };
}

function $PlayerIOS() {
    var newurl = "#";
    if (typeof(XgPlayer) != 'undefined') {
        newurl = XgPlayer['Url'].replace("ftp://", "xg://");
    }
    else if (typeof(Player) != 'undefined') {
        newurl = Player['Url'].replace("ftp://", "xg://");
    }
    var xuanjipage = top.location.href;
    if (typeof(XgPlayer['XuanJiPage']) != 'undefined') xuanjipage = XgPlayer['XuanJiPage'];
    if (typeof(XgPlayer['MobiAd']) != 'undefined')top.location.href = newurl + "|" + XgPlayer['MobiAd'] + "|" + xuanjipage;
    else top.location.href = newurl;
    installapp()();
}


// 添加---
function $GetBrowsers() {
    //   alert('我是浏览器获取');
    /*
     * 智能机浏览器版本信息:
     *
     */
    var browser = {
        versions: function () {
            var u = navigator.userAgent, app = navigator.appVersion;
            return {//移动终端浏览器版本信息
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }
//document.writeln("语言版本: "+browser.language+"<br/>");
    document.writeln(" 是否为移动终端: " + browser.versions.mobile + "<br/>");
    document.writeln(" ios终端: " + browser.versions.ios + "<br/>");
    document.writeln(" android终端: " + browser.versions.android + "<br/>");
//document.writeln(" 是否为iPhone: "+browser.versions.iPhone+"<br/>");
//document.writeln(" 是否iPad: "+browser.versions.iPad+"<br/>");
    //document.writeln(navigator.userAgent);
//alert("GetBrowser测试："+"<br/>"+navigator.userAgent)
    document.writeln("浏览器名称：" + navigator.appName + "<br/>");
    document.writeln("浏览器代码名称：" + navigator.appCodeName);
    alert(getBrowserInfo());
    alert("Post请求开始ii")
    // 进行ajax提交------------s
    $.ajax({
        type: "GET",
        
        url: "http://127.0.0.1:81/request.php",
        //data: { bundleid: "John", comment: "Bostonaaa" ,email:"4567225@qq.com"}
        //  data: "bundleid=John&comment=Bostonaaa&email=4567225@qq.com",

        success: function (msg) {
            document.writeln("Data Saved: " + msg);
            alert("Data Saved: " + msg);
        }
    })

    //进行ajax提交-----------e

}
function getBrowserInfo() {
    var agent = navigator.userAgent.toLowerCase();

    var regStr_ie = /msie [\d.]+;/gi;
    var regStr_ff = /firefox\/[\d.]+/gi
    var regStr_chrome = /chrome\/[\d.]+/gi;
    var regStr_saf = /safari\/[\d.]+/gi;
//IE
    if (agent.indexOf("msie") > 0) {
        return agent.match(regStr_ie);
    }

//firefox
    if (agent.indexOf("firefox") > 0) {
        return agent.match(regStr_ff);
    }

//Safari
    if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
        return agent.match(regStr_saf);
    }

//Chrome
    if (agent.indexOf("chrome") > 0) {
        return agent.match(regStr_chrome);
    }

}
//==================

function $PlayerAndroid() {
    // $GetBrowsers();
    // alert(navigator.userAgent+'t555')
    var finalurl;
    var newurl = "#";
    var isChrome = window.navigator.userAgent.indexOf("Chrome") !== -1;
  //  alert("Android设备");
    if (typeof(XgPlayer) != 'undefined') {
        newurl = XgPlayer['Url'];
    } else if (typeof(Player) != 'undefined') {
        newurl = Player['Url'];
    }

    var xuanjipage = top.location.href;
    if (typeof(XgPlayer['XuanJiPage']) != 'undefined') {
        xuanjipage = XgPlayer['XuanJiPage'];
    }

    if (typeof(XgPlayer['MobiAd']) != 'undefined') {
        finalurl = newurl + "|" + XgPlayer['MobiAd'] + "|" + xuanjipage;
    } else {
        finalurl = newurl;
    }

    var array = finalurl.split("//");
    finalurl = array[1];

    if (typeof AlipayWallet !== 'object') {
        AlipayWallet = {};
    }

    (function () {
        var ua = navigator.userAgent.toLowerCase(),
            locked = false,
            domLoaded = document.readyState === 'complete',
            delayToRun;

        function customClickEvent() {
            var clickEvt;
            if (window.CustomEvent) {
                clickEvt = new window.CustomEvent('click', {
                    canBubble: true,
                    cancelable: true
                });
            } else {
                clickEvt = document.createEvent('Event');
                clickEvt.initEvent('click', true, true);
            }

            return clickEvt;
        }

 
        var noIntentTest = /aliapp|360 aphone|weibo|windvane|safair|baidubrowser/.test(ua);
        var hasIntentTest = /chrome|samsung/.test(ua);
        var isAndroid = /android|adr/.test(ua) && !(/windows phone/.test(ua));
        var canIntent = !noIntentTest && hasIntentTest && isAndroid;
        //  alert(canIntent);
        AlipayWallet.open = function (params, jumpUrl) {
            if (!domLoaded && (ua.indexOf('360 aphone') > -1 || canIntent)) {
                // if (!domLoaded && (  canIntent)) {
                var arg = arguments;
                delayToRun = function () {
                    AlipayWallet.open.apply(null, arg);
                    delayToRun = null;
                };
                return;
            }

            // 唤起锁定，避免重复唤起
            if (locked) {
                return;
            }
            locked = true;

            var o;
            // 参数容错
            if (typeof params === 'object') {
                o = params;
            } else {
                o = {
                    params: params,
                    jumpUrl: jumpUrl
                };
            }

            // 是否为RC环境
            var isRc = '';

            // 是否唤起re包
            var isRe = '';
            if (typeof o.isRe === 'undefined') {
                o.isRe = !!isRe;
            }
            var tstart = new Date();
            // 唤醒app的scheme
            var schemePrefix = 'xg';

            //视频地址,替换成处理后的实际地址
            var address = finalurl;
            
            if (!canIntent) {
              //  alert("if-----" + intentUrl);
                var alipaysUrl = schemePrefix + '://' + address;

                //百度浏览器不支持xg,支持ftp协议
                var isBaidu = window.navigator.userAgent.indexOf("baidubrowser") !== -1;
                if (isBaidu) {
                    alipaysUrl = "ftp://" + address;
                }
            

                var ifr = document.createElement('iframe');
                ifr.src = alipaysUrl;
                ifr.style.display = 'none';
                document.body.appendChild(ifr);
            } else {

                // android 下 chrome 浏览器通过 intent 协议唤起钱包
                var intentUrl = 'intent://' + address + '#Intent;scheme=' + schemePrefix + ';package=tv.danmaku.ijk.media.demo' + ';end';
     
                try {
               
                 //    AppInterface.PlayVideo_Mi4("xg://"+address);
                    //  AppInterface.PlayVideo_Mi4('intent://'+address);
             
			//------------------------------------
                  //  document.getElementById('openApp').onclick = function (e) {
                        // 通过iframe的方式试图打开APP，如果能正常打开，会直接切换到APP，并自动阻止a标签的默认行为
                        // 否则打开a标签的href链接
                       // var ifrSrc = 'testjs://platformapi/startApp?name=tom&age=18';
						//var ifrSrc = 'xg://platformapi/' + 'intent://' + address+'?' ;
						var ifrSrc =  'xgplay://' + address   ;
					//	alert('ifrSrc注意:'+ifrSrc+"test-----" );
                        if (!ifrSrc) {
                            return;
                        }
                        var ifr = document.createElement('iframe');
                        ifr.src = ifrSrc;
                        ifr.style.display = 'none';
                        document.body.appendChild(ifr);
                        setTimeout(function () {
                            document.body.removeChild(ifr);

                        }, 1200);

                   // };

				 
                    // 其它浏览器
                //   else {
                      //  alert('else--2')
                        var e = document.createEvent("MouseEvents");
                        e.initEvent("click", true, true);
                        document.getElementById("openApp").dispatchEvent(e);
                 //   }

                    //==========================================================
		 
					 AppInterface.PlayVideo_Mi4("xg://"+address);
				     
                } catch (e) {
 
               
              //      alert("catch---360--13-"  );
                    //以下几步不能兼容所有版本的谷歌浏览器,个别版本的谷歌浏览器和Safari不支持非input标签的click事件,dispatchEvent捕捉不到,可以使用<intput type="button">的格式捕捉click事件
                    var openIntentLink = document.createElement('a');
                    openIntentLink.id = 'openIntentLink';
                    openIntentLink.style.display = 'none';


         
                    document.body.appendChild(openIntentLink);

                    openIntentLink.href = intentUrl;
                    // 执行click
                    openIntentLink.dispatchEvent(customClickEvent());
					
					 
					       
                }
            }

            // 延迟移除用来唤起钱包的IFRAME并跳转到下载页
            setTimeout(function () {
              //  alert("执行延时");
                //重定向地址,可以去掉，替换成弹出下载的悬浮框,支付宝网页并没有判断app是否存在,最后都跳转到下载页面
                var nElapsedMS = new Date() - tstart;
                if (window.navigator.userAgent.indexOf("baidubrowser") !== -1 && nElapsedMS > 1100) {//去掉安装了西瓜以后百度浏览器还弹下载apk的框
                    return;
                }
                top.location.href = "http://js.client51.com/xigua.apk";
            }, 1200)

            // 唤起加锁，避免短时间内被重复唤起
            setTimeout(function () {
                locked = false;
            }, 2500)
        }

        if (!domLoaded) {
            document.addEventListener('DOMContentLoaded', function () {
                domLoaded = true;
                //    alert(delayToRun);
                if (typeof delayToRun === 'function') {
                    delayToRun();
                }
            }, false);
        }
    })();

    (function () {
        var schemeParam = '';

        if (!location.hash) {
            AlipayWallet.open({
                params: schemeParam,
                jumpUrl: '',
                openAppStore: false
            });
        }
    })();
}

function $PlayerNt() {
    if (navigator.plugins) {
        var install = true;
        for (var i = 0; i < navigator.plugins.length; i++) {
            if (navigator.plugins[i].name == 'XiGua Yingshi Plugin') {
                install = false;
                break;
            }
        }
        if (!install) {
            player = '<div style="width:' + XgPlayer.Width + 'px;height:' + XgPlayer.Height + 'px;overflow:hidden;position:relative"><iframe src="' + XgPlayer.Buffer + '" scrolling="no" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0" name="buffer" id="buffer" style="position:absolute;z-index:2;top:0px;left:0px"></iframe><object  width="' + XgPlayer.Width + '" height="' + XgPlayer.Height + '" type="application/xgyingshi-activex" progid="xgax.player.1" param_URL="' + XgPlayer.Url + '" param_NextCacheUrl="' + XgPlayer.NextcacheUrl + '" param_LastWebPage="' + XgPlayer.LastWebPage + '" param_NextWebPage="' + XgPlayer.NextWebPage + '" param_OnPause="onPause" param_OnFirstBufferingStart="onFirstBufferingStart" param_OnFirstBufferingEnd="onFirstBufferingEnd" param_OnPlayBufferingStart="onPlayBufferingStart" param_OnPlayBufferingEnd="onPlayBufferingEnd" param_OnComplete="onComplete" param_Autoplay="1" id="xiguaPlayer" name="xiguaPlayer"></object></div>';
            if (XgPlayer.Second) {
                setTimeout("onAdsEnd()", XgPlayer.Second * 1000);
            }
            return player;
        }
    }
    return '<iframe border="0" src="' + XgPlayer.Installpage + '" marginWidth="0" frameSpacing="0" marginHeight="0" frameBorder="0" noResize scrolling="no" width="' + XgPlayer.Width + '" height="' + XgPlayer.Height + '" vspale="0" ></iframe>';
}
function $PlayerIe() {
    playerhtml = '<iframe src="' + XgPlayer.Buffer + '" id="buffer" width="' + XgPlayer.Width + '" height="' + (XgPlayer.Height - 80) + '" scrolling="no" frameborder="0" style="position:absolute;z-index:9;"></iframe><object classid="clsid:BEF1C903-057D-435E-8223-8EC337C7D3D0"  style="display:none" width="' + XgPlayer.Width + '" height="' + XgPlayer.Height + '" id="xiguaPlayer" name="xiguaPlayer" onerror="$XghdInstall();"><param name="URL" value="' + XgPlayer.Url + '"/><param name="NextCacheUrl" value="' + XgPlayer.NextcacheUrl + '"><param name="LastWebPage" value="' + XgPlayer.LastWebPage + '"><param name="NextWebPage" value="' + XgPlayer.NextWebPage + '"><param name="OnPlay" value="onPlay"/><param name="OnPause" value="onPause"/><param name="OnFirstBufferingStart" value="onFirstBufferingStart"/><param name="OnFirstBufferingEnd" value="onFirstBufferingEnd"/><param name="OnPlayBufferingStart" value="onPlayBufferingStart"/><param name="OnPlayBufferingEnd" value="onPlayBufferingEnd"/><param name="OnComplete" value="onComplete"/><param name="Autoplay" value="1"/></object>';
    return playerhtml;
}
function $PlayerIeBack() {
    if (browser == "Microsoft Internet Explorer") {
        if (xiguaPlayer.URL != undefined) {
            if (XgPlayer.Second) {
                setTimeout("onAdsEnd()", XgPlayer.Second * 1000);
            }
        }
        xiguaPlayer.ConfigurePlayer('url', XgPlayer.Url);
    }
}
//beta7版播放器回调函数
var onPlay = function () {
    $$('buffer').style.display = 'none';
    //强制缓冲广告倒计时
    if (XgPlayer.Second && xiguaPlayer.IsPlaying()) {
        xiguaPlayer.Play();
    }
}
var onPause = function () {
    $$('buffer').height = XgPlayer.Height - 63;
    $$('buffer').style.display = 'block';
}
var onFirstBufferingStart = function () {
    $$('buffer').height = Player.Height - 80;
    $$('buffer').style.display = 'block';
}
var onFirstBufferingEnd = function () {
    if (XgPlayer.Second) {
        xiguaPlayer.Play();
    } else {
        $$('buffer').style.display = 'none';
    }
}
var onPlayBufferingStart = function () {
    $$('buffer').height = XgPlayer.Height - 80;
    $$('buffer').style.display = 'block';
}
var onPlayBufferingEnd = function () {
    $$('buffer').style.display = 'none';
}
var onComplete = function () {
    onPause();
}
var onAdsEnd = function () {
    XgPlayer.Second = 0;
    $$('buffer').style.display = 'none';
    xiguaPlayer.style.display = 'block';
    setInterval("adshow()", 1000);
}
function adshow() {
    if (xiguaPlayer.IsPlaying()) {
        $$('buffer').style.display = 'none';
    } else if (xiguaPlayer.IsBuffing()) {
        $$('buffer').height = XgPlayer.Height - 63;
        $$('buffer').style.display = 'block';
    } else if (xiguaPlayer.IsPause()) {
        $$('buffer').height = XgPlayer.Height - 63;
        $$('buffer').style.display = 'block';
    } else {
        $$('buffer').height = XgPlayer.Height - 63;
        $$('buffer').style.display = 'block';
    }
}
var install = true;
playerhtml = $Showhtml();
$$("xg_box").innerHTML = playerhtml;
$PlayerIeBack();
